package com.heima.wemedia.controller;

import com.heima.common.dtos.PageResult;
import com.heima.common.dtos.ResponseResult;
import com.heima.model.media.dtos.WmNewsDto;
import com.heima.model.media.dtos.WmNewsPageReqDto;
import com.heima.model.media.dtos.WmNewsResultDTO;
import com.heima.wemedia.entity.WmNews;
import com.heima.wemedia.service.WmNewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author RMY
 * @Date 2021/11/27 16:06
 * @Version 1.0
 */
@RestController
public class WmNewsController {
    @Autowired
    private WmNewsService wmNewsService;

    /**
     * 查询所有文章
     * @param dto
     * @return
     */
    @PostMapping("/api/v1/news/page")
    public PageResult<WmNewsResultDTO> findByPage(@RequestBody WmNewsPageReqDto dto){
        return wmNewsService.findByPage(dto);
    }

    /**
     * 文章新增修改提交
     * @param dto
     * @return
     */
    @PostMapping("/api/v1/news/submit")
    public ResponseResult submit(@RequestBody WmNewsDto dto){
        wmNewsService.submit(dto);
        return ResponseResult.ok();
    }

    /**
     * 上架或下架
     * @param dto
     * @return
     */
    @PutMapping("/api/v1/news/down_or_up")
    public ResponseResult downOrUp(@RequestBody WmNewsDto dto){
        wmNewsService.downOrUp(dto);
        return ResponseResult.ok();
    }
    /**
     * 根据id查询文章
     * */
    @GetMapping("/api/v1/news/one/{id}")
    public ResponseResult<WmNews> findById(@PathVariable(value = "id") Integer id){


    return ResponseResult.ok(wmNewsService.findById(id));
    }
    /**
     * 删除自媒体文章
     * */
    @DeleteMapping("/api/v1/news/del_news/{id}")
    public ResponseResult deleteById(@PathVariable(value = "id") Integer id){
        wmNewsService.deleteById(id);
        return ResponseResult.ok();
    }
}
